package com.comment.config;

import com.comment.utils.LoginInterceptor;
import com.comment.utils.RefreshTokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求刷新token
        registry.addInterceptor(new RefreshTokenInterceptor(redisTemplate))
                .excludePathPatterns(
                        "/user/code",
                        "/user/login"
                );

        // 排除不需要拦截的路径
        registry.addInterceptor(new LoginInterceptor())
                .excludePathPatterns(
                        "/user/code",
                        "/user/login",
                        "/blog/hot",
                        "/shop/**",
                        "/shop-type/**",
                        "/voucher/**");

    }
}
